package per.hnvcam.util.rws;

import java.io.File;

public class ResourceMetadata {
   public static final int EXISTING = 1;
   public static final int NON_EXISTING = 0;

   private String resource;
   private int status;
   private long lastModified;
   private boolean canRead;
   private boolean canWrite;
   private boolean canExecute;

   private ResourceMetadata(String resource) {
      this.resource = resource;
   }

   public long lastModified() {
      return this.lastModified;
   }

   public boolean canRead() {
      return this.canRead;
   }

   public boolean canWrite() {
      return this.canWrite;
   }

   public boolean canExecute() {
      return this.canExecute;
   }

   public int getStatus() {
      return this.status;
   }
   
   public String getResource() {
      return this.resource;
   }

   public static final ResourceMetadata getMetadataFrom(String resource) {
      ResourceMetadata result = new ResourceMetadata(resource);
      File file = new File(resource);
      if (file.exists()) {
         result.lastModified = file.lastModified();
         result.canExecute = file.canExecute();
         result.canWrite = file.canWrite();
         result.canRead = file.canRead();
         result.status = EXISTING;
      } else {
         result.lastModified = System.currentTimeMillis();
         result.canExecute = false;
         result.canWrite = false;
         result.canRead = false;
         result.status = NON_EXISTING;
      }
      return result;
   }
}
